import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:taonile/config/config.dart';
import 'package:taonile/tabview/mine_collect_mall.dart';
import '../tabview/mine_collect_product.dart';

import '../tabview/order_list.dart';

///
/// 我的收藏
///
class MineCollectPage extends StatefulWidget {
  const MineCollectPage({Key? key}) : super(key: key);

  @override
  State<MineCollectPage> createState() => _MineCollectPageState();
}

class _MineCollectPageState extends State<MineCollectPage> {
  List<Widget> tabViews = [
    MineCollectProductPage(),
    MineCollectMallPage(),
  ];

  var tabNames = [
    '收藏商品',
    '收藏店铺 ',
  ];

  int _currentIndex = 0;

  //返回菜单item
  getMenuItem(int position) {
    return InkWell(
      onTap: () {
        setState(() {
          _currentIndex = position;
        });
      },
      child: Container(
        width: 374.w,
        decoration: BoxDecoration(color: Colors.transparent),
        padding: EdgeInsets.fromLTRB(0.w, 0, 0.w, 0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            _currentIndex == position
                ? Text(
                    tabNames[position],
                    style:
                        TextStyle(color: (Config.colorMain), fontSize: 25.sp),
                  )
                : Text(
                    tabNames[position],
                    style:
                        TextStyle(color: (Config.colorText1), fontSize: 25.sp),
                  ),
            Opacity(
              opacity: _currentIndex == position ? 1 : 0,
              child: Container(
                width: 80.w,
                margin: EdgeInsets.only(top: 6.w),
                child: Divider(
                  color: Config.colorMain,
                  height: 3.w,
                  thickness: 3.w,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Config.colorBg2,
      appBar: AppBar(
        title: const Text('我的收藏'),
        centerTitle: true,
      ),
      body: Container(
        width: double.infinity,
        height: double.infinity,
        child: Column(
          children: [
            Container(
              decoration: BoxDecoration(color: Config.colorWhite),
              width: double.infinity,
              height: 65.w,
              child: ListView.builder(
                itemCount: tabNames.length,
                padding: const EdgeInsets.symmetric(vertical: 0, horizontal: 0),
                shrinkWrap: true,
                scrollDirection: Axis.horizontal,
                physics: const BouncingScrollPhysics(),
                itemBuilder: (BuildContext context, int index) {
                  return getMenuItem(index);
                },
              ),
            ),
            Divider(
              color: Config.colorDivider,
              height: 2.w,
              thickness: 2.w,
            ),
            IndexedStack(
              index: _currentIndex,
              children: tabViews,
            )
          ],
        ),
      ),
    );
  }
}
